package com.ny.zmb.openapi.controller;

import com.alibaba.fastjson.JSONObject;
import com.ny.zmb.openapi.constant.PHPConstant;
import com.ny.zmb.openapi.controller.entity.Result;
import com.ny.zmb.openapi.entity.PmApiLog;
import com.ny.zmb.openapi.service.IPmApiLogService;
import com.ny.zmb.openapi.service.PmContractSignService;
import com.ny.zmb.openapi.service.PmRegisterService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.ny.zmb.openapi.constant.PHPConstant.*;

@RequestMapping("ys/contractSign")
@RestController
@CrossOrigin
public class YsContractSignController {
    @Resource
    private PmContractSignService pmContractSignService;
    @Resource
    private IPmApiLogService iPmApiLogService;

    @GetMapping(value = "contractSign")
    public Result contractSign(@RequestBody JSONObject obj, @RequestParam(required = false) String srcMerchantNo) {
        obj.put("notifyUrl", JAVA_BASE_URL + "/contractSignNotify");
        iPmApiLogService.save(new PmApiLog("ys/contractSign" + "/contractSign", obj.toJSONString()));
        return pmContractSignService.contractSign(obj, srcMerchantNo);
    }

    @GetMapping(value = "contractQuery")
    public Result contractQuery(@RequestBody JSONObject obj, @RequestParam(required = false) String srcMerchantNo) {
        iPmApiLogService.save(new PmApiLog("ys/contractSign" + "/contractQuery", obj.toJSONString()));
        return pmContractSignService.contractQuery(obj, srcMerchantNo);
    }

    @RequestMapping(value = "cancelContractSign")
    public Result cancelContractSign(@RequestBody JSONObject obj, @RequestParam(required = false) String srcMerchantNo) {
        iPmApiLogService.save(new PmApiLog("ys/contractSign" + "/cancelContractSign", obj.toJSONString()));
        return pmContractSignService.cancelContractSign(obj, srcMerchantNo);
    }

    @RequestMapping(value = "downloadContract")
    public Result downloadContract(@RequestBody JSONObject obj, @RequestParam(required = false) String srcMerchantNo) {
        iPmApiLogService.save(new PmApiLog("ys/contractSign" + "/downloadContract", obj.toJSONString()));
        return pmContractSignService.downloadContract(obj, srcMerchantNo);
    }
}
